<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui">

<ui:composition template="../layout/template.xhtml">
	<ui:define name="content">
		<h:form id="form">
			<p:commandButton value="Nova Notícia"
				action="#{noticiaController.prepararCadastroNoticia}" ajax="false" />

			<p:dataTable id="tableNews"
				value="#{noticiaController.noticiaDataModel}" rows="10"
				paginator="true"
				paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
				rowsPerPageTemplate="5,10,15" var="noticia"
				rowKey="#{noticia.titulo}" selection="#{noticiaController.noticia}"
				selectionMode="single">

				<p:ajax event="rowSelect" update=":form:panelDialog"
					oncomplete="newsDialog.show()" />

				<f:facet name="header">
					<h:outputText value="Notícias" />
				</f:facet>

				<p:column>
					<f:facet name="header">
						<h:outputText value="Título" />
					</f:facet>

					<h:outputText value="#{noticia.titulo}" />
				</p:column>

				<p:column>
					<f:facet name="header">
						<h:outputText value="Categoria" />
					</f:facet>

					<h:outputText value="#{noticia.categoria.nome}" />
				</p:column>

				<p:column>
					<f:facet name="header">
						<h:outputText value="Data" />
					</f:facet>

					<h:outputText value="#{noticia.date.time}" />
				</p:column>

				<p:column>
					<f:facet name="header">
						<h:outputText value="Alterar" />
					</f:facet>

					<p:commandButton value="" icon="ui-icon-arrowrefresh-1-w"
						actionListener="#{noticiaController.prepararAtualizarNoticia}"
						action="#{noticiaController.carregarAtualizarNoticia}"
						ajax="false">
					</p:commandButton>
				</p:column>

				<p:column>
					<f:facet name="header">
						<h:outputText value="Excluir" />
					</f:facet>


					<p:commandButton value="" icon="ui-icon-close"
						action="#{noticiaController.excluirNoticia}" ajax="false" />
				</p:column>
			</p:dataTable>

			<p:dialog id="dialog" header="Notícia" widgetVar="newsDialog"
				modal="true" resizable="false" showEffect="explode"
				hideEffect="explode">

				<h:panelGrid id="panelDialog" columns="1" cellpadding="4">

					<h:panelGrid columns="2">
						<h:outputText value="Título:" style="font-weight: bold;" />
						<h:outputText id="titulo"
							value="#{noticiaController.noticia.titulo}" />

						<h:outputText value="Categoria:" style="font-weight: bold;" />
						<h:outputText id="categoria"
							value="#{noticiaController.noticia.categoria.nome}" />

						<h:outputText value="Usuário:" style="font-weight: bold;" />
						<h:outputText id="usuario"
							value="#{noticiaController.noticia.user.nome}" />

						<h:outputText value="Data:" style="font-weight: bold;" />
						<h:outputText id="data"
							value="#{noticiaController.noticia.date.time}" />

					</h:panelGrid>

					<h:outputText value="Mensagem:" style="font-weight: bold;" />
					<h:outputText value="#{noticiaController.noticia.mensagem}"
						escape="false" />

				</h:panelGrid>
			</p:dialog>
		</h:form>
	</ui:define>
</ui:composition>
</html>